package models

import "blog_api/db"

type PrVisitControl struct {
	Id          int    `gorm:"column(id)" json:"id"`
	RandStr     string `gorm:"column(rand_str)" json:"rand_str"`
	CreateTime  uint64 `gorm:"column(create_time)" json:"create_time"`
	ValidTime   uint64 `gorm:"column(valid_time)" json:"valid_time"`
	InvalidTime uint64 `gorm:"column(invalid_time)" json:"invalid_time"`
}

func (*PrVisitControl) TableName() string {
	return "blog_pr_visit_control"
}


func AdminPrVisit(limit, offset int, field, keyword string) ([]PrVisitControl, int64) {
	var a []PrVisitControl
	var c int64
	l := db.Mysql.Model(&PrVisitControl{})
	if keyword != "" {
		ids, err := db.SearchKeyword(keyword, ES_LABEL_INDEX)
		if err != nil {
			return a, 0
		}
		l.Where("id in (?)", ids)
	}
	l.Count(&c)
	l.Select(field).Order("create_time desc").Limit(limit).Offset(offset).Scan(&a)
	return a, c
}